package tmproject.hlhj.fhp.tmvote.customView

import android.app.Activity
import android.content.Context
import android.view.LayoutInflater
import android.widget.PopupWindow
import android.widget.RelativeLayout
import kotlinx.android.synthetic.main.pop_choose.view.*
import tmproject.hlhj.fhp.tmvote.R

/**
 * Created by Never Fear   on 2018\8\22 0022.
Never More....
 */
class ChoosePop(private val context:Context,private val listener:OnPopChooseListener) :PopupWindow() {
    init {
        this.width=RelativeLayout.LayoutParams.MATCH_PARENT
        this.height=RelativeLayout.LayoutParams.WRAP_CONTENT
        isFocusable=true
        animationStyle=R.style.PopStyle
        enable()
    }

    private fun enable() {
        contentView=LayoutInflater.from(context).inflate(R.layout.pop_choose,null)

        contentView.btCamera.setOnClickListener {
            listener.camera()
            dismiss()
        }

        contentView.btPhoto.setOnClickListener {
            listener.photo()
            dismiss()

        }
        contentView.btDiss.setOnClickListener { dismiss() }
    }

    interface OnPopChooseListener{
        fun photo()
        fun camera()
    }

    override fun dismiss() {
        super.dismiss()
        if (context is Activity){
            val lp = context.window.attributes
            lp.alpha=1f
            context.window.attributes=lp
        }
    }
}